<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class NodeStoreRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'name' => 'required|unique:nodes|max:85',
            'path' => 'required|max:255',
            'pid' => 'required|integer',
            'icon' => 'required|max:255',
            'sort' => 'required|decimal:0,4',
            'status' => 'required|integer',
            'is_menu' => 'required|integer',
            'method' => 'required|max:255',
            'params' => 'max:255',
        ];
    }

    public function messages(): array
    {
        return [
            'name.required' => '节点名称不能为空',
            'name.unique' => '节点名称已存在',
            'name.max' => '节点名称最大长度为85',
            'path.required' => '节点路径不能为空',
            'path.max' => '节点路径最大长度为255',
            'pid.required' => '父级节点不能为空',
            'pid.integer' => '父级节点格式不正确',
            'icon.required' => '节点图标不能为空',
            'icon.max' => '节点图标最大长度为255',
            'sort.required' => '节点排序不能为空',
            'sort.decimal' => '节点排序格式不正确',
            'status.required' => '节点状态不能为空',
            'status.integer' => '节点状态格式不正确',
            'is_menu.required' => '是否菜单不能为空',
            'is_menu.integer' => '是否菜单格式不正确',
            'method.required' => '请求方法不能为空',
            'method.max' => '请求方法最大长度为255',
            'params.max' => '参数最大长度为255',
        ];
    }
}
